import {todoList} from "../types";
import {connection,query} from '../data/db'

let tableName = "todo"

export const addTodo = (newItem: todoList)=>{
    query(`insert into ${tableName} (\`content\`,\`status\`) values("${newItem.content}",${newItem.status});`,'')
};

export const getAllTodo = async ()=>{
    return await query(`select * from ${tableName};`,[]);

    return new Promise((resolve,reject)=>{
        connection.query(`select * from ${tableName}`,'',(err,res)=>{
            console.log(res);
            if ( err ) {
                reject( err )
            } else {
                resolve( res )
            }
        })
    });
}